fix(matcher): add workaround hint to invalid params warning#2662
fix(matcher): add workaround hint to invalid params warning#2662shanliuling wants to merge 2 commits intovuejs:mainfrom
Conversation
✅ Deploy Preview for vue-router canceled.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdjusts the dev-only warning emitted when resolving named-route navigation that discards invalid Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2662 +/- ##
=======================================
Coverage 85.66% 85.66%
=======================================
Files 86 86
Lines 10007 10007
Branches 2289 2289
=======================================
Hits 8572 8572
Misses 1422 1422
Partials 13 13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
posva
left a comment
There was a problem hiding this comment.
Thanks but this adds noise for all misses. It should only be displayed if the route is a named redirect with no params and the initial target location contained params
|
Hi @posva, I've updated the code to only show the workaround hint when the target route has no params AND the current location has params. This should avoid showing the hint for all redirect failures. The changes:
Please let me know if this matches your requirements. |
| expect('invalid param(s) "no", "foo" ').toHaveBeenWarned() | ||
| expect('invalid param(s) "no", "foo"').toHaveBeenWarned() | ||
| // workaround hint should be shown | ||
| expect('If you are using a catch-all route').toHaveBeenWarned() |
There was a problem hiding this comment.
shouldn't this not be shown? It would be nice to also have a dedicated unit test of the warning that is being added
|
The test still seems wrong and no new test has been added |
|
Hey @posva, thanks for the feedback! I've updated the tests to be more specific. Now there's a new test case checking that the hint only shows up when there are actually params from the initial location, just like you suggested. I also split the tests to make sure we're not adding noise when there aren't any params to suggest. Let me know if this looks good to you! |
posva
left a comment
There was a problem hiding this comment.
The tests still do not look good: they don't showcase the redirect issue and the warning seems to appear even without it
e68daaf to
e900bb7
Compare
packages/router/src/matcher/index.ts
Outdated
| if (invalidParams.length) { | ||
| // Check if this is a catch-all route (contains pathMatch) with a named redirect | ||
| const isCatchAllWithRedirect = | ||
| matcher!.record.path.includes('pathMatch') && // catch-all route |
There was a problem hiding this comment.
It’s not about the shape of the path, you need to check for params being passed implicitly.
|
Hi @posva, thanks for pointing out the implicit params logic! You were completely right—checking the shape of the path was fundamentally flawed. I have completely refactored the approach:
This should be fully aligned with your intended logic. Please take a look! |
What is the problem?
When using a catch-all route with a named redirect like:
Users see a warning:
Discarded invalid param(s) "pathMatch" when navigating.The warning message doesn't explain how to fix the issue.
How did I fix it?
Enhanced the warning message to include a helpful workaround hint:
If you are using a catch-all route with a named redirect, pass an empty params object: redirect: { name: '...', params: {} }.This matches the workaround suggested by @posva in the issue comments.
How was this tested?
packages/router/__tests__/warnings.spec.tsto match the new warning formatCloses #1617
Summary by CodeRabbit
Bug Fixes
Tests